package com.iafme.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.iafme.configuration.LoginConfiguration;
import com.iafme.dto.req.LoginReqDTO;
import com.iafme.dto.req.WebMemberReqDTO;
import com.systemframework.constants.Constants;
import com.systemframework.sys.configuration.CaptchaConfiguration;
import com.systemframework.sys.dto.request.LoginRequestDTO;
import com.systemframework.sys.dto.response.CaptchaResponseDTO;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author summer
 * @version 1.0
 * @date 2025/1/21 19:05
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/web")
public class WebLoginController {

    private final CaptchaConfiguration captchaConfiguration;

    private final LoginConfiguration loginConfiguration;

    @RequestMapping(value = "/captcha")
    public Result<CaptchaResponseDTO> code() {
        return Result.successResult(this.captchaConfiguration.captcha());
    }


    @PostMapping(value = "/login")
    public SaTokenInfo login(@RequestBody LoginRequestDTO loginReqDTO){

        return loginConfiguration.login(loginReqDTO);
    }


    @PostMapping(value = "/reg")
    public String reg(@Valid @RequestBody WebMemberReqDTO webMemberReqDTO){
        loginConfiguration.reg(webMemberReqDTO);
        return Constants.SUCESS;
    }

    @PutMapping(value = "/modifyPsd")
    public String modifyPsd(@Valid @RequestBody WebMemberReqDTO webMemberReqDTO){
        loginConfiguration.modifyPsd(webMemberReqDTO);
        return Constants.SUCESS;
    }

}
